package com.heitian.ssm.controller;

import com.google.gson.JsonObject;
import com.heitian.ssm.model.Suggestion;
import com.heitian.ssm.service.SuggestionService;
import com.heitian.ssm.utils.CommonUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 作者： 陈建峰
 * 创建时间： 18/3/28 下午11:27
 * 版本： [1.0, 18/3/28]
 * 描述： <描述>
 */
@Controller
@RequestMapping("/Suggestion")
public class SuggestionController {

    @Resource
    SuggestionService suggestionService;

    @RequestMapping(value = "/SaveSuggestion", method = RequestMethod.POST)
    public void SaveFeedBack(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        response.setHeader("Content-type", "text/html;charset=UTF-8");
        JsonObject paras = CommonUtils.getJson(request);
        if (paras == null) {
            response.getWriter().write(CommonUtils.createJson("0", "", null).toString());
            return;
        }
        String suggestion = paras.get("suggestion").getAsString();
        String userGuid = paras.get("userGuid").getAsString();
        String userName = paras.get("userName").getAsString();
        Suggestion suggest = new Suggestion();
        suggest.setUserGuid(userGuid);
        suggest.setUserName(userName);
        suggest.setCreatTime(CommonUtils.getCurrentTime());
        suggest.setSuggestion(suggestion);
        suggest.setSuggestionGuid(CommonUtils.GetUUID());
        suggestionService.SaveSuggestion(suggest);
        response.getWriter().write(CommonUtils.createJson("1", "添加成功！", null).toString());
    }
}
